package edu.kit.aifb.ruleintegrator.bayes.network;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.jgrapht.DirectedGraph;
import org.jgrapht.graph.DefaultDirectedGraph;



public class Network {
	
	DirectedGraph<RandomVariable,Edge> m_graph;
	
	public Network(){
		m_graph=new DefaultDirectedGraph<>(Edge.class);
	}
	
	public void addVariable(RandomVariable var){
		m_graph.addVertex(var);
	}
	
	public List<RandomVariable> getParents(RandomVariable var){
		List<RandomVariable> res=new ArrayList<RandomVariable>();
		Set<Edge> edges=m_graph.incomingEdgesOf(var);
		for(Edge edge:edges){
			RandomVariable v=m_graph.getEdgeSource(edge);
			res.add(v);
			
		}
		return res;
	}
	
	public List<RandomVariable> getChilds(RandomVariable var){
		List<RandomVariable> res=new ArrayList<RandomVariable>();
		Set<Edge> edges=m_graph.outgoingEdgesOf(var);
		for(Edge edge:edges){
			RandomVariable v=m_graph.getEdgeTarget(edge);
			res.add(v);			
		}
		return res;
	}
	
	public void addEdge(RandomVariable src, RandomVariable tgt){
		m_graph.addEdge(src, tgt);
	}

}
